
package com.wica.view;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;

import com.wica.facetube.R;

public class InitialConfiguration extends Activity implements OnKeyListener{
	// *************** Constants ************** //
	// Log constants
    protected static final String LOG_TAG = "__FT.InitialConfiguration__";

	// *************** Methods **************************** //
    @Override
	protected void onCreate(Bundle savedInstanceState) {   	
        // Be sure to call the super class.
        super.onCreate(savedInstanceState);
        if (!internetNetworkAvailable())
        	showDialog(1);
        else {
            this.startActivity(new Intent(InitialConfiguration.this, ListOfMoviesTabs.class));
            this.startActivity(new Intent(InitialConfiguration.this, TextLocationDialog.class));
        	this.startActivity(new Intent(InitialConfiguration.this, MoodDialog.class));
        	finish();
        }// if
    }// onCreate method
    
    protected boolean internetNetworkAvailable() {
        // Local Variables
    	ConnectivityManager connectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo[] allNetworkInfo = connectivityManager.getAllNetworkInfo();
        int i;
        
        for (i=0;i<allNetworkInfo.length;i++){
        	NetworkInfo networkInfoItem = allNetworkInfo[i];        	
            if (networkInfoItem.isAvailable()){
            	return true;
            }// if
        }// for
		return false;
	}// internetNetworkAvailable method

	protected Dialog onCreateDialog(int id) {
    	return new AlertDialog.Builder(this)
        		.setIcon(R.drawable.stat_sample)
        		.setTitle("No Internet connection was found")
                .setMessage("You need an internet connection in order to use the application")                
                .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    	finish();  
                    }// onclick method
                })
                .create();
    }//onCreateDialog method
	
	@Override
	public boolean onKey(View v, int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			finish();
			return true;
  	  	}else {
  	  		return super.onKeyDown(keyCode, event);
  	  	}
	}// onKey method	
    
}// InitialConfiguration class